import baseRequest from '../base'
import { DateModel } from '@/utils/date'

export async function getLabelTypeList() {
  const res = await baseRequest({
    url: 'label/query_basis_label_type',
    method: 'post'
  })
  if (res.resultCode === '9001') {
    return res.result
  }
}

export async function getBasisLabelList(data) {
  const res = await baseRequest({
    url: 'label/query_basis_label_list',
    method: 'post',
    data
  })
  if (res.resultCode === '9001') {
    return res.result
  }
}

// 新增组合标签 label/create_combination_label
export async function getCreateCombinationLabel(data) {
  const res = await baseRequest({
    url: 'label/create_combination_label',
    method: 'post',
    data
  })
  if (res.resultCode === '9001') {
    return res
  }
}

// 分页获取组合标签列表
export async function getCombinationLabelList(data) {
  const res = await baseRequest({
    url: 'label/query_combination_label_list',
    method: 'post',
    data
  })
  if (res.resultCode === '9001') {
    for (let i = 0; i < res.result.content.length; i++) {
      res.result.content[i].createDate = DateModel.timestampToDate(res.result.content[i].createDate, false).split(' ')[0]
      if (res.result.content[i].updateTime) {
        res.result.content[i].updateTime = DateModel.timestampToDate(res.result.content[i].updateTime, false).split(' ')[0]
      }
    }
    return res.result
  }
}

/**
 * 删除组合标签
 * @param labelIds 删除的组合标签id集合 Array [id, id]
 */
export async function getCombinationLabelDelete(data) {
  const res = await baseRequest({
    url: 'label/delete',
    method: 'post',
    data
  })
  if (res.resultCode === '9001') {
    return res
  }
}

/**
 * 更改组合标签配置
 * @param labelId
 * @param name
 * @param status
 * @param combinationLabelValueList
 */
export async function getUpdateCombinationLabel(data) {
  const res = await baseRequest({
    url: 'label/update_combination_label',
    method: 'post',
    data
  })
  if (res.resultCode === '9001') {
    return res
  }
}

// 查询标签详情
export async function getCombinationLabelDetail(labelId) {
  const res = await baseRequest({
    url: `label/query_detail/${labelId}`,
    method: 'get'
  })
  if (res.resultCode === '9001') {
    return res
  }
}
